package com.example.uilt;

import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Component;

@Component
public class CodeUtil {

    // 方法一
    public static String getCode(String tele){

        // 要求可以生成以0开头的验证码
        if(tele.startsWith("0")){
            return String.valueOf((int)((Math.random()*9+1)*100000));
        }
        return String.valueOf((int)((Math.random()*9+1)*100000));

    }
    // 方法二（使用方法二）
    public static String generatorCode(String tele){
        int hash=tele.hashCode();
        int encryption=123456;
        long result=hash^encryption;
        long nowTime=System.currentTimeMillis();
        result=result^nowTime;
        long code=result%1000000;
        code=code<0?-code:code;
        return code+"";
    }
    @Cacheable(value="smsCode",key="#tele")
    public String get(String tele){
        return null;
    }

    public static void main(String[] args) {
        System.out.println(getCode("1"));
        System.out.println(new CodeUtil().generatorCode("18866668888"));
    };
}
